/** ******************** String工具类************** */
// trim去掉字符串两边的指定字符,默去空格
String.prototype.trim = function(tag) {
	if (!tag) {
		tag = '\\s';
	} else {
		if (tag == '\\') {
			tag = '\\\\';
		} else if (tag == ',' || tag == '|' || tag == ';') {
			tag = '\\' + tag;
		} else {
			tag = '\\s';
		}
	}
	eval('var reg=/(^' + tag + '+)|(' + tag + '+$)/g;');
	return this.replace(reg, '');
};
// 字符串截取后面加入...
String.prototype.interceptString = function(len) {
	if (this.length > len) {
		return this.substring(0, len) + "...";
	} else {
		return this;
	}
}
// 将一个字符串用给定的字符变成数组
String.prototype.toArray = function(tag) {
	if (this.indexOf(tag) != -1) {
		return this.split(tag);
	} else {
		if (this != '') {
			return [ this.toString() ];
		} else {
			return [];
		}
	}
}
// 只留下数字(0123456789)
String.prototype.toNumber = function() {
	return this.replace(/\D/g, "");
}
// 保留中文
String.prototype.toCN = function() {
	var regEx = /[^\u4e00-\u9fa5\uf900-\ufa2d]/g;
	return this.replace(regEx, '');
}
// 转成int
String.prototype.toInt = function() {
	var temp = this.replace(/\D/g, "");
	return isNaN(parseInt(temp)) ? this.toString() : parseInt(temp);
}
// 是否是以XX开头
String.prototype.startsWith = function(tag) {
	return this.substring(0, tag.length) == tag;
}
// 是否已XX结尾
String.prototype.endWith = function(tag) {
	return this.substring(this.length - tag.length) == tag;
}
// StringBuffer
var StringBuffer = function() {
	this._strs = new Array;
};
StringBuffer.prototype.append = function(str) {
	this._strs.push(str);
};
StringBuffer.prototype.toString = function() {
	return this._strs.join("");
};
String.prototype.replaceAll = function(s1, s2) {
	return this.replace(new RegExp(s1, "gm"), s2);
}